﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CSTest
{
    class ListTest
    {
        public void RandomSelectListItem()
        {
            List<string> sl = new List<string>();
            sl.Add("1");
            sl.Add("2");
            sl.Add("3");
            sl.Add("4");

            Random r = new Random();
            List<string> result = new List<string>();
            List<int> b = new List<int>();
            int i = 0;
            while (i < 3 && i < sl.Count)
            {
                int a = r.Next(sl.Count);
                if (b.Contains(a))
                    continue;
                b.Add(a);
                result.Add(sl[a]);//将取出的数放入到目的集合中
                i++;
            }
            foreach (var item in result)
            {
                Console.WriteLine(item);
            }

        }
    }
}
